package com.golddaymicromall.activity.setting.personal;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.golddaymicromall.activity.R;
import com.golddaymicromall.activity.setting.personal.address.AddressActivity;
import com.golddaymicromall.activity.setting.personal.bankcard.Card_mybankActivity;
import com.golddaymicromall.activity.setting.personal.UpdateAvatarActivity;
import com.golddaymicromall.activity.setting.personal.SafeEditPwdActivity;
import com.golddaymicromall.base.BaseActivity;
import com.golddaymicromall.img.HeadImageLoad;
import com.golddaymicromall.model.HttpModel;
import com.golddaymicromall.util.SPUtils;

public class PersonalInfoActivity extends BaseActivity implements View.OnClickListener{
    private LinearLayout mSafeEditPwd;
    private LinearLayout mPersonalEditAddress;
    private LinearLayout mpersonal_bankcard;
    private LinearLayout mActivity_personal_Avatar;
    private HeadImageLoad headImageLoad;
    private ImageView mUserHead;
    private LinearLayout mPersonalBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal_info);
        initView();
        headImageLoad = new HeadImageLoad();
        String headImgName = SPUtils.get(getApplicationContext(), "headImg", "").toString();
        if(!"".equals(headImgName)){
            Glide.with(this)
                    .load(HttpModel.HEADIMGURL + headImgName).placeholder(R.drawable.me_denglu_head)
                    .into(mUserHead);
        }
    }

    public void initView(){
        mSafeEditPwd = (LinearLayout) findViewById(R.id.safe_editpwd);
        mPersonalEditAddress = (LinearLayout) findViewById(R.id.personal_editAddress);
        mpersonal_bankcard = (LinearLayout) findViewById(R.id.personal_bankcard);
        mActivity_personal_Avatar = (LinearLayout) findViewById(R.id.activity_personal_avatar);
        mUserHead = (ImageView) findViewById(R.id.setting_UserHead);
        mPersonalBack = (LinearLayout) findViewById(R.id.activity_personal_info_btn_back);
        mSafeEditPwd.setOnClickListener(this);
        mpersonal_bankcard.setOnClickListener(this);
        mPersonalEditAddress.setOnClickListener(this);
        mActivity_personal_Avatar.setOnClickListener(this);
        mPersonalBack.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.safe_editpwd:
                Intent intent_editpwd = new Intent(this,SafeEditPwdActivity.class);
                startActivity(intent_editpwd);
                break;
            case R.id.personal_editAddress:
                Intent intent_address = new Intent(this,AddressActivity.class);
                startActivity(intent_address);
                break;
            case R.id.personal_bankcard:
                Intent bankcard = new Intent(this,Card_mybankActivity.class);
                startActivity(bankcard);
                break;
            case R.id.activity_personal_avatar:
                Intent updateAvatar = new Intent(this,UpdateAvatarActivity.class);
                startActivity(updateAvatar);
                break;
            case R.id.activity_personal_info_btn_back:
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        headImageLoad = new HeadImageLoad();
        String headImgName = SPUtils.get(getApplicationContext(), "headImg", "").toString();
        if(!"".equals(headImgName)){
            headImageLoad.LoadImg(headImgName,mUserHead);
        }
    }
}
